package net.bbtang.website.utils;
 
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer; 
  
public class CustomizedPropertyPlaceholderConfigurer extends 
         PropertyPlaceholderConfigurer { 

	private static Map<String, Object> ctxPropertiesMap = new HashMap<String, Object>();
	
	private String[] encryptPropNames = {"jdbc.username","jdbc.password"};
	
    @Override 
    protected void processProperties( 
             ConfigurableListableBeanFactory beanFactoryToProcess, 
             Properties props) throws BeansException { 
    	
    	for (Object key : props.keySet()) { 
    		String keyStr = key.toString();		
    		//String value  = convertProperty (keyStr,props.getProperty(keyStr));
    		String value = props.getProperty(keyStr);
    		props.setProperty(keyStr, value);
    		ctxPropertiesMap.put(keyStr, value); 
    	}   
    	super.processProperties(beanFactoryToProcess, props); 
    } 
    
//    @Override
//    protected String convertProperty(String propertyName,String propertyValue){
//    	if(isEncryptProp(propertyName)){
//    		return DESUtils.decrypt(propertyValue);
//    	}else{
//    		return propertyValue;
//    	}
//    }

//    private boolean isEncryptProp(String propertyName){
//    	
//    	for(String encryptPropName : encryptPropNames){
//    		if(encryptPropName.equals(propertyName)){
//    			return true;
//    		}
//    	}
//    	return false;
//    }
    
    public static Object getContextProperty(String name) { 
    	return ctxPropertiesMap.get(name); 
    } 
    public static void setContextProperty(String name,String param) { 
    	ctxPropertiesMap.put(name, param); 
    } 
    
    
} 